﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MyCode.Project.Domain.Message.Response.User;
using MyCode.Project.Infrastructure.Constant;
using MyCode.Project.WebApi.Controllers;
using MyCode.Project.Domain.Config;
using MyCode.Project.Infrastructure.UnityExtensions;
using MyCode.Project.Services;

namespace MyCode.Project.WebApi.Areas.Wechat.Controllers
{
    public class BaseWechatController : BaseAPIController
    {
        /// <summary>
        /// 取得登录信息
        /// </summary>
        protected MemberLoginInfo CurrentLogin
        {
            get
            {

                var obj = this.RequestContext.RouteData.Values[Const.LoginInfoKey];

                var loginInfo = ((JObject)obj).ToObject<MemberLoginInfo>();

                var service = UnityHelper.GetService<ICheckTokenService>();


                if (loginInfo != null)
                {
                    if (!service.CheckToken(loginInfo))
                    {
                        throw new Exception("");
                    }
                }

                return loginInfo;


            }
        }
    }
}
